package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlReportDetail;
import com.ruoyi.sl.pojo.SlReportDetailQuery;
import com.ruoyi.sl.pojo.SlSinglePayQuery;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlWagesDay;
import com.ruoyi.sl.service.ISlWagesDayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日工资Controller
 * 
 * @author admin
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/sl/wagesday")
public class SlWagesDayController extends BaseController
{
    @Autowired
    private ISlWagesDayService slWagesDayService;

    /**
     * 查询日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlWagesDay slWagesDay)
    {
        clearPage();
        startPage();
        //查询范围
        LoginUser loginUser = getLoginUser();
        if (SecurityUtils.hasRole("admin")) {

        }else if (SecurityUtils.hasRole("checkpass")) {

        }else{
            slWagesDay.setUserName(loginUser.getUsername());
        }
        List<SlWagesDay> list = slWagesDayService.selectSlWagesDayList(slWagesDay);
        return getDataTable(list);
    }

    @GetMapping("/querylist")
    public TableDataInfo querylist(SlSinglePayQuery slSinglePayQuery)
    {
        clearPage();
        startPage();
        //查询范围
        LoginUser loginUser = getLoginUser();
        if (SecurityUtils.hasRole("admin")) {
            slSinglePayQuery.setRfworkUser(null);
        }else if (SecurityUtils.hasRole("checkpass")) {
            slSinglePayQuery.setRfworkUser(null);
        }else if(SecurityUtils.hasRole("rwork")){
            slSinglePayQuery.setRfworkUser(loginUser.getUsername());
        }else{
            slSinglePayQuery.setRfworkUser(null);
            slSinglePayQuery.setNickName(null);
            slSinglePayQuery.setUserName(loginUser.getUsername());
        }
        List<SlWagesDay> list = slWagesDayService.selectSlWagesDayByQuery(slSinglePayQuery);
        return getDataTable(list);
    }




    /**
     * 查询计件日工资列表
     */
//    @PreAuthorize("@ss.hasPermi('sl:wagesday:list')")
//    @GetMapping("/plist")
//    public TableDataInfo piecelist(SlWagesDay slWagesDay)
//    {
//        startPage();
//        List<SlWagesDay> list = slWagesDayService.selectSlWagesDayListByPiece(slWagesDay);
//        return getDataTable(list);
//    }


    /**
     * 查询计件日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:list')")
    @GetMapping("/plist")
    public TableDataInfo piecelist(SlReportDetailQuery slReportDetailQuery)
    {
        startPage();
        List<SysRole> roleList = getLoginUser().getUser().getRoles();
        //查询范围
        LoginUser loginUser = getLoginUser();

        if (loginUser.getUser().isAdmin())
        {

        } else if (SecurityUtils.hasRole("checkpass")) {
            
        }else if (SecurityUtils.hasRole("rwork")) {
            slReportDetailQuery.setRfowrkUser(loginUser.getUsername());
        }else{
            slReportDetailQuery.setUserName(loginUser.getUsername());
        }

        List<SlReportDetail> list = slWagesDayService.selectReportDetail(slReportDetailQuery);
        return getDataTable(list);
    }

    /**
     * 查询零工日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:list')")
    @GetMapping("/olist")
    public TableDataInfo oddjoblist(SlReportDetailQuery slReportDetailQuery)
    {
        startPage();
        //查询范围
        LoginUser loginUser = getLoginUser();
        if (loginUser.getUser().isAdmin())
        {

        } else if (SecurityUtils.hasRole("checkpass")) {

        }else if (SecurityUtils.hasRole("rwork")) {
            slReportDetailQuery.setRfowrkUser(loginUser.getUsername());
        }else{
            slReportDetailQuery.setUserName(loginUser.getUsername());
        }
        List<SlReportDetail> list = slWagesDayService.selectOddjobReportDetail(slReportDetailQuery);
        return getDataTable(list);
    }

    /**
     * 查询系数日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:list')")
    @GetMapping("/clist")
    public TableDataInfo coefficientlist(SlReportDetailQuery slReportDetailQuery)
    {
        startPage();
        //查询范围
        LoginUser loginUser = getLoginUser();
        if (loginUser.getUser().isAdmin())
        {

        } else if (SecurityUtils.hasRole("checkpass")) {

        }else if (SecurityUtils.hasRole("rwork")) {
            slReportDetailQuery.setRfowrkUser(loginUser.getUsername());
        }else{
            slReportDetailQuery.setUserName(loginUser.getUsername());
        }
        List<SlReportDetail> list = slWagesDayService.selectSlWagesDayListByCoefficient(slReportDetailQuery);
        return getDataTable(list);
    }

    /**
     * 导出日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:export')")
    @Log(title = "日工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlWagesDay slWagesDay)
    {
        List<SlWagesDay> list = slWagesDayService.selectSlWagesDayList(slWagesDay);
        ExcelUtil<SlWagesDay> util = new ExcelUtil<SlWagesDay>(SlWagesDay.class);
        util.exportExcel(response, list, "日工资数据");
    }


    /**
     * 计件日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:export')")
    @Log(title = "日工资", businessType = BusinessType.EXPORT)
    @PostMapping("/exportp")
    public void exportp(HttpServletResponse response, SlReportDetailQuery slReportDetailQuery)
    {
        List<SlReportDetail> list = slWagesDayService.selectReportDetail(slReportDetailQuery);
        ExcelUtil<SlReportDetail> util = new ExcelUtil<SlReportDetail>(SlReportDetail.class);
        util.newExportExcel(response, list, "日工资数据");
    }

    /**
     * 系数日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:export')")
    @Log(title = "日工资", businessType = BusinessType.EXPORT)
    @PostMapping("/exportc")
    public void exportc(HttpServletResponse response, SlReportDetailQuery slReportDetailQuery)
    {
        List<SlReportDetail> list = slWagesDayService.selectSlWagesDayListByCoefficient(slReportDetailQuery);
        ExcelUtil<SlReportDetail> util = new ExcelUtil<SlReportDetail>(SlReportDetail.class);
        util.newExportExcel(response, list, "日工资数据");
    }

    /**
     * 零工日工资列表
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:export')")
    @Log(title = "日工资", businessType = BusinessType.EXPORT)
    @PostMapping("/exporto")
    public void exporto(HttpServletResponse response, SlReportDetailQuery slReportDetailQuery)
    {
        List<SlReportDetail> list = slWagesDayService.selectOddjobReportDetail(slReportDetailQuery);
        ExcelUtil<SlReportDetail> util = new ExcelUtil<SlReportDetail>(SlReportDetail.class);
        util.exportExcel(response, list, "日工资数据");
    }
    /**
     * 获取日工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:query')")
    @GetMapping(value = "/{wagesDayId}")
    public AjaxResult getInfo(@PathVariable("wagesDayId") Long wagesDayId)
    {
        return success(slWagesDayService.selectSlWagesDayByWagesDayId(wagesDayId));
    }

    /**
     * 新增日工资
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:add')")
    @Log(title = "日工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlWagesDay slWagesDay)
    {
        return toAjax(slWagesDayService.insertSlWagesDay(slWagesDay));
    }

    /**
     * 修改日工资
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:edit')")
    @Log(title = "日工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlWagesDay slWagesDay)
    {
        return toAjax(slWagesDayService.updateSlWagesDay(slWagesDay));
    }

    /**
     * 删除日工资
     */
    @PreAuthorize("@ss.hasPermi('sl:wagesday:remove')")
    @Log(title = "日工资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wagesDayIds}")
    public AjaxResult remove(@PathVariable Long[] wagesDayIds)
    {
        return toAjax(slWagesDayService.deleteSlWagesDayByWagesDayIds(wagesDayIds));
    }

}
